<?php
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Academic Free License (AFL 3.0)
 * that is bundled with this package in the file LICENSE_AFL.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/afl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * @category    design
 * @package     base_default
 * @copyright   Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
 * @license     http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */

/**
 * Product description template
 *
 * @see Mage_Catalog_Block_Product_View_Description
 */
?>
<?php $_TabNew = $this->getProduct()->getDescription();
$_product = $this->getProduct();
$_helper = $this->helper('catalog/output'); ?>
<?php if ($_TabNew): ?>
    <h2><?php echo $this->__('Details') ?></h2>
    <div class="std">
        <?php echo $this->helper('catalog/output')->productAttribute($this->getProduct(), $_description, 'description') ?>
	          <?php 
           $productId = $this->getRequest()->getParam('id');
                     $array= $this->getdataproductview($productId);
                     $sumarray = count($array);
                   //  echo 'sum array: '. $sumarray;
                     if($sumarray >=0) :
        ?>
        
    <div>
          
             <!-- <?php// echo $this->getReviewsSummaryHtml($_product, false, true)?>-->
             <span onclick="check()" id="writereview" style="  background-color: #E9E9E9;cursor: pointer;font-weight: bold;font-size: 13px;display:block">Write a Review this product</span><p></p>
             <span onclick="check1()" id="writereview1" style="  background-color: #E9E9E9;cursor: pointer;font-weight: bold;font-size: 13px;display:none">Write a Review this product</span><p></p>
<div class="review-form-div" id="display_review" style="font-size: 11px;display: none">
<?php echo $this->getChildHtml('review_form') ?> 
<?php echo $this->getLayout()->createBlock('review/form')->setBlockId('product.review.form')->toHtml() ?> 
</div> 
               <script type="text/javascript">
 function check()
 {
     //alert('hello');
     var flag=true;
     if(flag==true)
         {
     document.getElementById("display_review").style.display = 'block';
    document.getElementById("writereview1").style.display = 'block';
     document.getElementById("writereview").style.display = 'none';
    
         }

 }
 function check1()
 {
     //alert('hello');
     document.getElementById("display_review").style.display = 'none';
    document.getElementById("writereview1").style.display = 'none';
     document.getElementById("writereview").style.display = 'block';

 }
</script>
              <?php 
                $reviewData = Mage::getModel('review/review/summary'); 
             //    echo 'number of reviews: ' . $reviewData->getTotalReviews($_product->getId());

?>
             
<!--			  <a href="<?php// echo $this->getReviewsUrl() ?>"><?php //echo $this->__('%d Review(s)', $reviewData->getTotalReviews($_product->getId())) ?></a>            -->
               <span><?php echo $this->__('%d Review(s)', $reviewData->getTotalReviews($this->getRequest()->getParam('id'))) ?></span>
               <div id="showall" onclick="showall()" style="display: block"><span style="text-decoration: underline;font-weight: bold;cursor: pointer;">Show All >></span></div> 
               <div id="hidden" onclick="funhidden()" style="display: none"><span style="text-decoration: underline;font-weight: bold;cursor: pointer;"><< Hidden</span></div>        
        <input type="hidden" id="sumreview" value="<?php echo $reviewData->getTotalReviews($this->getRequest()->getParam('id'))?>"></input>            
        <div id="showdata" >             
  <?php 
                     $productId = $this->getRequest()->getParam('id');
                     $sku= $this->getdataproductview($productId);
            		 $getname = $this->getnameproduct($productId);
				     echo '<br/>';
				     $count=0;
				    		     foreach($sku as $item)
				     {
                                         $count=$count+1;
     echo '<div id="noidung_'.$count.'" style="border-bottom:1px solid #BFBFBF;margin-bottom:10px">';
				       
				   if($item['customer_id'] == null || $item['customer_id']=='')
				     {
				         $type ='Guest';
				     }
				     else
				     {
				         $type ='Customer';
				     }
				     if($item['customer_id']=='0')
				     {
				         $type ='Admin';
				     }
                    echo   '<div >';
                    echo     '<b>'.$item['nickname']. '</b> on  ';
                    echo     ''.date('M d, Y', strtotime($item['created_at'])). ' ('.$getname->getName().' ) ';
                    echo   '</div>';
                    
             $resource = Mage::getSingleton('core/resource');
                                    $readConnection = $resource->getConnection('core_read');
                                    $table = $resource->getTableName('rating_option_vote');
                                    $query ='SELECT entity_pk_value, review_id,percent,value url_path From '.$table.' WHERE review_id ='.$item['review_id'].' AND entity_pk_value= '.$productId.' ORDER BY review_id DESC LIMIT 0,20 ';
                                    $newitem = $readConnection->fetchAll($query); 
                                   // print_r($newitem);
                           foreach($newitem as $newsitem)
                             {
             echo   '<div style="margin-bottom: 40px;margin-left: -8px;margin-top: 7px;">';       
             echo            '<div style="width:85px;float:left" >';
                        
                          echo                 '<div id="rating_cont" >	';
                          echo                  '<div id="rating_btns" ">';
                          echo                      '<ul>';
                          echo                         '<li>0.5</li>';
                          echo                         '<li>1.0</li>';  
                          echo                         '<li>1.5</li>'; 
                          echo                         '<li>2.0</li>'; 
                          echo                         '<li>2.5</li>'; 
                          echo                         '<li>3.0</li>'; 
                          echo                         '<li>3.5</li>'; 
                          echo                         '<li>4.0</li>'; 
                          echo                         '<li>4.5</li>'; 
                          echo                         '<li>5.0</li>'; 
                          echo                     '</ul>';
                          echo                   '</div>';
                          echo                  '<div id="rating_on" style="width:'.$newsitem['percent'].'%"></div>';
                          echo                  '</div>';
                                                                   
                           }    
                           
            
              
                     echo       '</div>';
                echo           '<div style="float:right;width:890px"><p>'.$item['title'].' </p> </div>';
              echo      '</div>';
              echo           '<div>';
              echo            '<p>'.$item['detail'].'</p>';
              echo           '</div>';
              echo            '<br/>';
              echo '</div>';            
                                   }
                                   //end foreach
                     ?> 
            <br/>
        </div>
    </div>
        <?php endif?>
        <script type="text/javascript">
           // window.onload = function ()
                 var sumreview1= document.getElementById("sumreview").value;
                 //alert(sumreview1);
                 var x=1;
                 for(x;x<sumreview1;x++)
                     {
                         if(x<4)
                             {
                         document.getElementById("noidung_"+x).style.display='block';
                             }
                         else
                             {
                            document.getElementById("noidung_"+x).style.display='none'; 
                             }
                     }
                function showall()
                {
                            document.getElementById("showall").style.display='none';
                            document.getElementById("hidden").style.display='block';
                            var i=1;
                               for(i;i<sumreview1;i++)
                     {
                         document.getElementById("noidung_"+i).style.display='block';
                     }
                }
                 function funhidden()
                {
                            document.getElementById("showall").style.display='block';
                            document.getElementById("hidden").style.display='none';
                            var j=1;
                              for(j;j<sumreview1;j++)
                     {
                         
                         if(j<4)
                             {
                         document.getElementById("noidung_"+j).style.display='block';
                             }
                         else
                             {
                                document.getElementById("noidung_"+j).style.display='none'; 
                             }
                     }
                }
        </script>
 </div>
<br/>
<?php endif; ?> 
